package com.chaosj.skill.prometheus

import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import io.micrometer.core.instrument.Timer;
import java.util.concurrent.TimeUnit

/**
 * @Description:
 * @author caoyangjie
 * @date 2020年01月2020/1/14日 14:08
 * @Copyright: © 赢时胜
 */
class TimerSample {
    static void main(args){
        Timer timer = Timer.builder("timer")
                .tag("timer","timer")
                .description("timer")
                .register(new SimpleMeterRegistry())
        timer.record({ ->
            try {
                TimeUnit.SECONDS.sleep(2)
            }catch (InterruptedException e){
                //ignore
            }
        })
        System.out.println(timer.count())
        System.out.println(timer.measure())
        System.out.println(timer.totalTime(TimeUnit.SECONDS))
        System.out.println(timer.mean(TimeUnit.SECONDS))
        System.out.println(timer.max(TimeUnit.SECONDS))
    }
}
